home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Snippets / Stuart's Tech Notes / Dialog Manager < prev    next >
Text File  |  1994-12-10  |  2KB  |  28 lines

  1. (C) 1992 Stuart Cheshire <cheshire@cs.stanford.edu>
  2.  
  3. This note addresses a deficiency in Apple's documentation (and code).
  4.  
  5. Inside Mac suggests that good programs use resources and bad programs use constants embedded in the program. Therefore good programs use GetNewDialog to read dialog resources, bad programs use NewDialog and specify all the parameters.
  6.  
  7. Also, smart programs do intelligent memory allocation and supply storage for dialog records. Dumb programs just pass NULL and let the dialog manager allocate space on the heap (causing it to get fragmented).
  8.  
  9. Putting these two together (using GetNewDialog and supplying the memory for it) creates a dialog box for which there is no correct method of closing, according to the Apple documentation.
  10.  
  11. The word in Inside Mac I page 414 says (paraphrased):
  12.  
  13. If you call NewDialog with a NULL storage parameter, you should call DisposDialog.
  14. If you call NewDialog with your own storage parameter, you should call CloseDialog.
  15. If you call GetNewDialog with a NULL storage parameter, you should call DisposDialog.
  16. If you call GetNewDialog with a your own storage parameter, you should call ????
  17.  
  18. The problem is that, in this case, you provide the DialogRecord storage, and the Dialog Manager provides the item list storage. DisposDialog will dispose of both (wrong) and CloseDialog will dispose of neither (wrong).
  19.  
  20. The word from Apple DTS:
  21.  
  22. >> Thanks for your note on a memory leak with "CloseDialog".  You're
  23. >> absolutely right that this is a bug in the Dialog Manager;
  24. >> furthermore, there's nothing we can do about it, thanks to the number
  25. >> of developers who are currently already manually disposing of the
  26. >> DITL; thus, that's what I suggest: first, use CloseDialog to close it,
  27. >> then manually dispose of the dialog's item list with DisposeHandle.
  28.